Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Better versioned history #209

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Feb 8, 2024

Issue #10

May require silverstripe/silverstripe-versioned-admin#198 to be merged in order for archive admin to work properly

Note that for elemental page history where you have block with a has_one linkfield on it, the value for this nested field will not display. This is consistent with nested file's not showing on the history of an elemental-file-block with a linked file on it which also does not show on the page history. In both instances, clicking on the "Block history" link will show the value of nested field

@emteknetnz emteknetnz mentioned this pull request Feb 8, 2024
@emteknetnz emteknetnz force-pushed the pulls/4/version-history branch 4 times, most recently from b7eab31 to acbbed5 Compare February 12, 2024 06:07
@emteknetnz emteknetnz marked this pull request as ready for review February 12, 2024 06:09
@@ -5,7 +5,6 @@ import { connect } from 'react-redux';
import { DndContext, closestCenter, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
import { restrictToVerticalAxis, restrictToParentElement } from '@dnd-kit/modifiers';
import { injectGraphql } from 'lib/Injector';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is unrelated refactoring to remove an unused import

*/
const LinkField = ({
value = null,
onChange,
onNonPublishedVersionedState,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is unrelated refactoring to remove a non-existent prop

setLoading(false);
// isSorting is set to true on drag start and only set to false here to prevent
// the loading indicator for flickering
setIsSorting(false);
})
.catch(() => {
actions.toasts.error(i18n._t('LinkField.FAILED_TO_LOAD_LINKS', 'Failed to load links'))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to not show a red toast here because this will pop up when viewing old versions of an owner where the link has been deleted. I've changed this to show an inline message when the link fails to load.

@@ -350,7 +362,7 @@ const LinkField = ({

LinkField.propTypes = {
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
onChange: PropTypes.func.isRequired,
onChange: PropTypes.func,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never have been a required field as it only makes sense in an entwine context

@@ -23,6 +23,7 @@ const LinkModalContainer = ({ types, typeKey, linkID = 0, isOpen, onSuccess, onC
// which will causes bugs with validation
if (!LinkModal) {
setLinkModal(() => loadComponent(`LinkModal.${handlerName}`));
return;
Copy link
Member Author

@emteknetnz emteknetnz Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should is to fix a console error where the state hasn't yet been updated from the call the setLinkModal, meaning that the <LinkModal> jsx object doesn't yet exist at time of render because LinkModal hasn't yet been set. Setting the state via this hook will trigger a rerender in which time <LinkModal> will not exist

@@ -21,7 +21,7 @@ if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') {
"LinkField.LINK_MODIFIED_TITLE": "Link has unpublished changes",
"LinkField.LINK_MODIFIED_LABEL": "Modified",
"LinkField.CANNOT_CREATE_LINK": "Cannot create link",
"LinkField.FAILED_TO_LOAD_LINKS": "Failed to load links",
"LinkField.FAILED_TO_LOAD_LINKS": "Failed to load link(s)",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor improvement to the message as it's used for both LinkField and for MultiLinkField

*/
const LinkField = ({
value = null,
onChange,
onNonPublishedVersionedState,
onChange = () => {},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a default value that's being set now that it's no longer a required prop

@@ -66,16 +76,21 @@ test('LinkField will render loading indicator if ownerID is not 0', async () =>
expect(container.querySelectorAll('.link-picker')).toHaveLength(1);
});

test('LinkField will render link-picker if ownerID is not 0 and has finished loading', async () => {
test('LinkField will render link-picker if ownerID is not 0 and isMulti and has finished loading', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This jest test was technically wrong before - it shouldn't render a .link-picker element if it's non-isMulti and ownerID is not 0 - it should only render that if it's isMulti

@emteknetnz emteknetnz force-pushed the pulls/4/version-history branch 3 times, most recently from 1d6eb0b to 2d01f5b Compare February 12, 2024 06:31
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to fulfil this acceptance critera (or deem it too hard for this card and open a separate card for them):

Archived Admin uses the same behaviour as Versionned Admin when displaying link.

If I click on an archived page from archive admin, I see:
image

Note that there was a link in both the "Has one link" and "Has many links one" field, but not the "Has many links two" field.

LinkField on versioned history view correctly identify if a Link was attached to the page, but the Link was deleted.

This doesn't seem to work.

  1. Create a link on a page
  2. Publish the page
  3. Archive the link
  4. Make a change to the page and publish it again
  5. View the version of the page which did have the link

For me it shows "Failed to load link(s)"

Issue with archived history

When I archive a page (which has links on it), then restore the page from archived, then in the history tab I try to view the archive version, I get an infinite loading component.

@emteknetnz
Copy link
Member Author

Archived Admin uses the same behaviour as Versionned Admin when displaying link.

ArchivedAdmin support adds a level of complexity over the regular history viewer that I don't think is worth it. We need to support multiple permutations of owner and links archived and not-archived. The LinkFieldController which handles all the data isn't aware of this. We also need to add support for knowing if we're even in an archived admin which is very messy because of the special treatment given to SiteTree vs other dataobjects.

LinkField on versioned history view correctly identify if a Link was attached to the page, but the Link was deleted.

This relates to the point above. Because the link was deleted then when attempting to fetch the link via LinkFieldController it will return a 404. We could change the message from "Failed to load link(s)" to "Link was deleted" ... but then again that's an assumption because it may be 404'ing for a different reason. I'd say it's such a minor point we should just leave as is.

Issue with archived history

I was unable to replicate this issue

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, definitely an improvement over how it was before. Just a bit of tidy up.

src/Form/LinkField.php Outdated Show resolved Hide resolved
src/Form/MultiLinkField.php Outdated Show resolved Hide resolved
@emteknetnz emteknetnz force-pushed the pulls/4/version-history branch 2 times, most recently from eace65b to 79e6307 Compare February 13, 2024 23:57
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GuySartorelli GuySartorelli merged commit 58bd7a7 into silverstripe:4 Feb 14, 2024
12 checks passed
@GuySartorelli GuySartorelli deleted the pulls/4/version-history branch February 14, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants